package com.hunktimes.wholesale.vm

import androidx.lifecycle.MutableLiveData
import com.hunktimes.wholesale.base.BaseViewModel
import com.hunktimes.wholesale.extension.launch
import com.hunktimes.wholesale.net.WholeSaleRepository

/**
 * Author: Delete
 * Date: 2020/8/12 10:03
 * Description:
 *
 */
class CategoryVM : BaseViewModel() {
    val categoryTagResult = MutableLiveData<List<String>>()

    val categoryTag = MutableLiveData<String>()

    fun getCategoryTags() {
        launch({
            val resp = WholeSaleRepository.getCategoryTags()
            val tags = resp.data
            tags?.let {
                categoryTagResult.value = it
            }
        })
    }

    fun queryCategoryByTag() {
        val tag = categoryTag.value
        if (tag.isNullOrBlank())
            return
        launch({
            val resp = WholeSaleRepository.queryCategoryByTag(tag)
            val tags = resp.data
            tags?.let {
                categoryTagResult.value = it
            }
        })
    }
}